package com.schoolcloud.social.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.social.entity.SocBardFollow;
import com.schoolcloud.social.service.SocBardFollowService;
import com.schoolcloud.social.mapper.SocBardFollowMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hongmizfb
 * @description 针对表【soc_bard_follow(贴吧关注表)】的数据库操作Service实现
 * @createDate 2025-02-20 15:49:48
 */
@Service
public class SocBardFollowServiceImpl extends ServiceImpl<SocBardFollowMapper, SocBardFollow>
        implements SocBardFollowService {

    @Override
    public Long getFollowerCountByUserId(String userId) {
        return lambdaQuery().eq(SocBardFollow::getUserId, userId).count();
    }

    @Override
    public Long getFollowerCountByBardId(String bardId) {
        return lambdaQuery().eq(SocBardFollow::getBardId, bardId).count();
    }

    @Override
    public boolean isFollow(String bardId, String userId) {
        return lambdaQuery().eq(SocBardFollow::getBardId, bardId).eq(SocBardFollow::getUserId, userId).exists();
    }

    @Override
    public List<Integer> getFollowBardByUserId(String userId) {
        return lambdaQuery().eq(SocBardFollow::getUserId, userId).list().stream().map(SocBardFollow::getBardId).collect(Collectors.toList());
    }

    @Override
    public List<SocBardFollow> getUserListByBardId(String bardId) {
        return lambdaQuery().eq(SocBardFollow::getBardId, bardId).list();
    }

    @Override
    public void deleteFollow(SocBardFollow socBardFollow) {
        lambdaUpdate().eq(SocBardFollow::getBardId, socBardFollow.getBardId())
                .eq(SocBardFollow::getUserId, socBardFollow.getUserId()).remove();
    }
}




